package com.lizhi.menu.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizhi.menu.Dto.InvitationDto;
import com.lizhi.menu.common.response.Result;
import com.lizhi.menu.domain.Invitation;
import com.lizhi.menu.service.IInvitationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 帖子Controller
 *
 * @author lizhi
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/system/invitation")
@RequiredArgsConstructor
@Api(tags = "帖子管理")
public class InvitationController {
    private final IInvitationService invitationService;

    /**
     * 查询帖子列表
     */
    @GetMapping("/list")
    @ApiOperation("查询帖子列表")
    public Result<Page<Invitation>> list(InvitationDto invitation) {
        return Result.ok(invitationService.selectInvitationList(invitation));
    }

    /**
     * 查询帖子列表
     */
    @GetMapping("/my")
    @ApiOperation("查询我的帖子列表")
    public Result<Page<Invitation>> my(InvitationDto invitation) {
        invitation.setUserId(Long.parseLong(StpUtil.getLoginId().toString()));
        return Result.ok(invitationService.selectInvitationList(invitation));
    }

    /**
     * 获取帖子详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取帖子详细信息")
    public Result<Invitation> getInfo(@PathVariable("id") String id) {
        return Result.ok(invitationService.selectInvitationById(id));
    }

    /**
     * 新增帖子
     */
    @PostMapping
    @ApiOperation("新增帖子")
    public Result<Void> add(@RequestBody Invitation invitation) {
        invitation.setUserId(StpUtil.getLoginId().toString());
        invitationService.insertInvitation(invitation);
        return Result.ok();
    }

    /**
     * 修改帖子
     */
    @PutMapping
    @ApiOperation("修改帖子")
    public Result<Void> edit(@RequestBody Invitation invitation) {
        invitationService.updateInvitation(invitation);
        return Result.ok();
    }

    /**
     * 删除帖子
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("删除帖子")
    public Result<Void> remove(@PathVariable String id) {
        invitationService.remove(id);
        return Result.ok();
    }
}
